#A script to take line csv files and tranform them into one full csv file
#readable by sqlite
lines = ['C1', 'C2', 'FASTCAT', 'E', 'E1', 'E2', 'NITECAT', 'AB']
#Operation days for busses
weekdays = "1, 1, 1, 1, 1, 0, 0"
E1 = "0, 0, 0, 0, 0, 1, 1"
E2 = "0, 0, 0, 0, 0, 1, 0"
NITECAT = "0,0,0,0,1,1,0"
stopDesc = "None"
stops = []
with open('fullTable.sql', 'w') as f:
  f.write("")
for busline in lines:
  if busline == 'NITECAT':
    opDays == NITECAT
  elif busline == 'E1':
    opDays == E1
  elif busline == 'E2':
    opDays == E2
  else:
    opDays = weekdays
  with open(busline + '.csv', 'r') as f:
    for line in f:
      line = line.split(',')
      line.pop() #last item in list is formatting shit and not a real time so ignore it
      if len(line): #Don't add an empty line
        stops.append([line.pop(0), line])
  maxRow = len(stops)
  #empty the file if there's anything in it
  with open('fullTable.sql', 'a') as f:
    for i in range(0, len(stops)):
      for j in range(0, len(stops[i][1])):
#	write line, opDays, stopName,  stopTime, seqNum
        f.write(busline + ', ' + 'none' + ', ' + opDays + ', ' + stops[i][0] + ', ' + stopDesc + ', ' + stops[i][1][j] + ', ' + str(maxRow * j + i) + ', 0, 0\n')
  del stops[:]
